home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / mouclib5 / mouselib.c next >
C/C++ Source or Header  |  1995-11-01  |  31KB  |  798 lines

  1. /***************************************************************************
  2. *                               MouseLib.c                                 *
  3. ***************************************************************************/
  4. #include <dos.h>
  5. #include <stdio.h>
  6. #include <graphics.h>
  7. #include "mouselib.h"
  8.  
  9. unsigned interceptX, interceptY ;
  10. void far (*interrupt OldExitProc)(void);
  11.  
  12. enum boolean  mouse_present    ;
  13. enum mouseType  mouse_buttons  ;
  14. unsigned  eventX,eventY,eventButtons ; /* any event handler should update */
  15. enum boolean eventhappened  ;        /* these vars to use getLastEvent   */
  16. unsigned XMotions, YMotions ;        /*          per 8 pixels            */
  17.  
  18. static unsigned data ;            /* data segment (DS) */
  19.  
  20. struct box HideBox ;             /* Do not change field order !!! */
  21. struct REGPACK reg ;             /* general registers used */
  22. static struct SREGS sreg ;              /* segment registers */
  23.  
  24. int grMode,grDrv   ;             /* detect graphic mode if any */
  25. int grCode         ;             /* return initgraph code in here */
  26. u_int LastMask = 0 ;
  27. enum boolean mouseGraph = FALSE; /* assume text mode upon entry */
  28.  
  29. signed int mouseCursorLevel ;        /* if > 0 mouse cursor is visiable,
  30.                                         otherwise not, containes the level
  31.                                         of showMouseCursor/hideMouseCursor */
  32.  
  33. void far interrupt (*lastHandler)(void) ; /* when changing the interrupt
  34.                                              handler temporarily, save BEFORE
  35.                                              the change these to variables,
  36.                                              and restore them when neccessary */
  37.  
  38. struct grCursorType lastCursor  ; /* when changing graphic cursor temporarily,
  39.                                      save these values BEFORE the change, and
  40.                                      restore when neccessary */
  41.  
  42.  
  43. /***************************************************************************/
  44. /*                mouseLib - C version  -      Release 5                   */
  45. /*                                                                         */
  46. /* because of quirks in hercules graphic mode that is not detectable       */
  47. /*  by the mouse driver we have to know when we initMouse if we want       */
  48. /*  to check for graphic mode or not, if we do we must perform a           */
  49. /*  setMouseGraph before initGraph, to initGraph in text mode we must      */
  50. /*  resetMouseGraph before.. , if these calling conventions are not        */
  51. /*  taken we might have problems in hercules cards!                        */
  52. /*                                                                         */
  53. /* each call to hideMouseCursor must be balanced by a matching call        */
  54. /*  to showMouseCursor, 2 calls to hideMou.. and only 1 to showM..         */
  55. /*  will not show the mouse cursor on the screen!                          */
  56. /***************************************************************************/
  57.  
  58. static u_int WatchData[] = {
  59.     0xE007,0xC003,0x8001,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8001,
  60.     0xC003,0xE007,0x0,0x1FF8,0x318C,0x6186,0x4012,0x4022,0x4042,0x718C,
  61.     0x718C,0x4062,0x4032,0x4002,0x6186,0x318C,0x1FF8,0x0
  62.    };
  63.  
  64. static u_int newWatchCursor[] = {
  65.     0xffff, 0xc003, 0x8001, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  66.     0x0, 0x0, 0x0, 0x0, 0x8001, 0xc003, 0xffff, 0x0, 0x0,
  67.     0x1ff8, 0x2004, 0x4992, 0x4022, 0x4042, 0x518a, 0x4782,
  68.     0x4002, 0x4992, 0x4002, 0x2004, 0x1ff8, 0x0, 0x0
  69.    };
  70.  
  71. static u_int ArrowData[] = {
  72.     0xFFFF,0x8FFF,0x8FFF,0x87FF,0x83FF,0x81FF,0x80FF,0x807F,0x803F,
  73.     0x801F,0x800F,0x801F,0x807F,0x887F,0xDC3F,0xFC3F,
  74.     0x0,0x0,0x2000,0x3000,0x3800,0x3C00,0x3E00,0x3F00,0x3F80,0x3FC0,
  75.     0x3FE0,0x3E00,0x3300,0x2300,0x0180,0x0180
  76.    };
  77.  
  78. static u_int UpArrowCursor[] = {
  79.     0xf9ff,0xf0ff,0xe07f,0xe07f,0xc03f,0xc03f,0x801f,0x801f,
  80.     0xf,0xf,0xf0ff,0xf0ff,0xf0ff,0xf0ff,0xf0ff,0xf0ff,
  81.     0x0,0x600,0xf00,0xf00,0x1f80,0x1f80,0x3fc0,0x3fc0,
  82.     0x7fe0,0x600, 0x600, 0x600, 0x600, 0x600, 0x600, 0x600
  83.    };
  84.  
  85. static u_int LeftArrowCursor[] = {
  86.     0xfe1f,0xf01f,0x0,   0x0,   0x0,   0xf01f,0xfe1f,0xffff,
  87.     0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  88.     0x0,   0xc0,  0x7c0, 0x7ffe,0x7c0, 0xc0,  0x0,   0x0,
  89.     0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0
  90.    };
  91.  
  92. static u_int CheckMarkCursor[] = {
  93.     0xfff0,0xffe0,0xffc0,0xff81,0xff03,0x607, 0xf,   0x1f,
  94.     0xc03f,0xf07f,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  95.     0x0,   0x6,   0xc,   0x18,  0x30,  0x60,  0x70c0,0x1d80,
  96.     0x700, 0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0
  97.    };
  98.  
  99. static u_int PointingHandCursor[] = {
  100.     0xe1ff,0xe1ff,0xe1ff,0xe1ff,0xe1ff,0xe000,0xe000,0xe000,
  101.     0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,
  102.     0x1e00,0x1200,0x1200,0x1200,0x1200,0x13ff,0x1249,0x1249,
  103.     0xf249,0x9001,0x9001,0x9001,0x8001,0x8001,0x8001,0xffff
  104.    };
  105.  
  106. static u_int DiagonalCrossCursor[] = {
  107.     0x7e0, 0x180, 0x0,   0xc003,0xf00f,0xc003,0x0,   0x180,
  108.     0x7e0, 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  109.     0x0,   0x700e,0x1c38,0x660, 0x3c0, 0x660, 0x1c38,0x700e,
  110.     0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0
  111.    };
  112.  
  113. static u_int RectangularCrossCursor[] = {
  114.     0xfc3f,0xfc3f,0xfc3f,0x0,0x0,   0x0,   0xfc3f,0xfc3f,
  115.     0xfc3f,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
  116.     0x0,   0x180, 0x180, 0x180, 0x7ffe,0x180, 0x180, 0x180,
  117.     0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0,   0x0
  118.    };
  119.  
  120. static u_int HourGlassCursor[] = {
  121.     0x0,   0x0,   0x0,   0x0,   0x8001,0xc003,0xe007,0xf00f,
  122.     0xe007,0xc003,0x8001,0x0,   0x0,   0x0,   0x0,   0xffff,
  123.     0x0,   0x7ffe,0x6006,0x300c,0x1818,0xc30, 0x660, 0x3c0,
  124.     0x660, 0xc30, 0x1998,0x33cc,0x67e6,0x7ffe,0x0,   0x0
  125.    };
  126.  
  127.  
  128. /***************************************************************************
  129. *                               callMouse();                               *
  130. *                                                                          *
  131. * used to call mouse interrupt with global data reg - used as parameters   *
  132. ***************************************************************************/
  133. void callMouse(void)
  134. {
  135.         intr(MOUSEINT,®);
  136.  
  137. }; /* callMouse(); */
  138.  
  139. /******************************************************************************
  140. *                                  initMouse                                  *
  141. * For some reason grCode is assigned a value of -11,(0xFFF5) in the second time*
  142. *  we call initmouse after we allready are in graphics mode, override.. was   *
  143. *  born because of that situation.                                            *
  144. ******************************************************************************/
  145. void initMouse (void)
  146. {
  147.     enum boolean overRideDriver ; /*  TRUE if we over-ridden stupid driver
  148.                                       hercules bug  */
  149.     overRideDriver = FALSE;
  150.  
  151.     if (mouseGraph && (peek (0,0x449) == 7)) { /*  assume no mda - hercules  */
  152.       poke (0,0x449,6);
  153.       overRideDriver = TRUE;
  154.     };
  155.  /* trick stupid mouse driver to know we are in graphic mode */
  156.     reg.r_ax = 0;          /* detect genius mouse */
  157.     reg.r_bx = 0;          /* be sure what mode we get */
  158.     callMouse();
  159.     mouse_present = (reg.r_ax != 0) ? TRUE : FALSE ; /* not an iret.. */
  160.     if ((reg.r_bx & 2) != 0)
  161.         mouse_buttons = twoButton;
  162.     else if ((reg.r_bx & 3) != 0)
  163.         mouse_buttons = threeButton;
  164.     else mouse_buttons = another; /* unknown to us */
  165.  
  166.     if (overRideDriver) poke (0,0x449,7) ;
  167.  
  168.  /* restore the stupid situation */
  169.     eventX = eventY = eventButtons = 0;
  170.     eventhappened = FALSE;
  171.     XMotions = 8;
  172.     YMotions = 16;
  173.     mouseCursorLevel = 0; /*  not visiable, one show to appear  */
  174. }; /* initMouse */
  175.  
  176. /***************************************************************************
  177. *                                doMouse                                   *
  178. *  First function one should call, before even thinking of using the mouse *
  179. ****************************************************************************/
  180. void doMouse (void)
  181. {
  182.    segread(&sreg) ;
  183.    data = sreg.ds ;              /* data is a global variable */
  184.  
  185.    eventX = eventY = 0;
  186.  
  187.    eventhappened = FALSE;        /* initialize ... */
  188.     initMouse();                  /*detect in global variables*/
  189.     setArrowCursor();             /*start like that in graphic mode*/
  190. /*    OldExitProc = ExitProc;
  191.     ExitProc    = MyExitProc; */
  192. } /*doMouse*/
  193.  
  194.  
  195. /***************************************************************************
  196. *                            showMouseCursor                               *
  197. ****************************************************************************/
  198. void showMouseCursor (void)
  199. {
  200.     reg.r_ax = 1; /* enable cursor display */
  201.     callMouse();
  202.     mouseCursorLevel++;
  203. }; /* showMouseCursor */
  204.  
  205. /***************************************************************************
  206. *                            hideMouseCursor                               *
  207. ****************************************************************************/
  208. void hideMouseCursor (void)
  209. {
  210.     reg.r_ax = 2; /* disable cursor display */
  211.     callMouse();
  212.     mouseCursorLevel--;
  213. }; /* hideMouseCursor */
  214.  
  215. /***************************************************************************
  216. *                               getMouseX                                  *
  217. ****************************************************************************/
  218. unsigned getMouseX  (void)
  219. {
  220.     reg.r_ax = 3;
  221.     callMouse();
  222.     return reg.r_cx;
  223. }; /* getMouseX */
  224.  
  225. /***************************************************************************
  226. *                               getMouseY                                  *
  227. ****************************************************************************/
  228. unsigned getMouseY  (void)
  229. {
  230.     reg.r_ax = 3;
  231.     callMouse();
  232.     return reg.r_dx;
  233. }; /* getMouseX */
  234.  
  235. /***************************************************************************
  236. *                               getButton                                  *
  237. ****************************************************************************/
  238. enum buttonState getButton(char Button)
  239. {
  240.     reg.r_ax = 3;
  241.     callMouse();
  242.     if ((reg.r_bx & Button) != 0)
  243.         return buttonDown;
  244.         /* bit 0 = left, 1 = right, 2 = middle */
  245.     else return buttonUp;
  246. }; /* getButton */
  247.  
  248. /***************************************************************************
  249. *                             buttonPressed                                *
  250. ****************************************************************************/
  251. enum boolean buttonPressed (void)
  252. {
  253.     reg.r_ax = 3;
  254.     callMouse();
  255.     if ((reg.r_bx & 7) != 0)
  256.         return TRUE;
  257.     else return FALSE;
  258. }; /* buttonPressed */
  259.  
  260. /***************************************************************************
  261. *                             setMouseCursor                               *
  262. ****************************************************************************/
  263. void setMouseCursor(unsigned x, unsigned y)
  264.  
  265. {
  266.    reg.r_ax = 4;
  267.    reg.r_cx = x;
  268.    reg.r_dx = y; /* prepare parameters */
  269.    callMouse();
  270. }; /* setMouseCursor */
  271.  
  272. /***************************************************************************
  273. *                               lastXPress                                 *
  274. ****************************************************************************/
  275. unsigned lastXPress(char Button)
  276. {
  277.     reg.r_ax = 5;
  278.     reg.r_bx = Button;
  279.     callMouse();
  280.     return reg.r_cx;
  281. }; /* lastXpress */
  282.  
  283. /***************************************************************************
  284. *                               lastYPress                                 *
  285. ****************************************************************************/
  286. unsigned lastYPress(char Button)
  287. {
  288.     reg.r_ax = 5;
  289.     reg.r_bx = Button;
  290.     callMouse();
  291.     return reg.r_dx;
  292. }; /* lastYpress */
  293.  
  294. /***************************************************************************
  295. *                             buttonPresses                                *
  296. ****************************************************************************/
  297. unsigned buttonPresses(char Button) /* from last check */
  298. {
  299.     reg.r_ax = 5;
  300.     reg.r_bx = Button;
  301.     callMouse();
  302.     return reg.r_bx;
  303. }; /* buttonPresses */
  304.  
  305. /***************************************************************************
  306. *                              lastXRelease                                *
  307. ****************************************************************************/
  308. unsigned lastXRelease(char Button)
  309. {
  310.     reg.r_ax = 6;
  311.     reg.r_bx = Button;
  312.     callMouse();
  313.     return reg.r_cx;
  314. }; /* lastXRelease */
  315.  
  316. /***************************************************************************
  317. *                              lastYRelease                                *
  318. ****************************************************************************/
  319. unsigned lastYRelease(char Button)
  320.  
  321. {
  322.     reg.r_ax = 6;
  323.     reg.r_bx = Button;
  324.     callMouse();
  325.     return reg.r_dx;
  326. }; /* lastYRelease */
  327.  
  328. /***************************************************************************
  329. *                             buttonReleases                               *
  330. ****************************************************************************/
  331. unsigned buttonReleases(char Button) /* from last check */
  332. {
  333.     reg.r_ax = 6;
  334.     reg.r_bx = Button;
  335.     callMouse();
  336.     return reg.r_bx;
  337. }; /* buttonReleases */
  338.  
  339. /***************************************************************************
  340. *                                  swap                                    *
  341. ****************************************************************************/
  342. void swap(unsigned *a, unsigned *b)
  343. {
  344.     unsigned c;
  345.      c = *a;
  346.     *a = *b;
  347.     *b =  c;  /* swap a and b */
  348. }; /* swap */
  349.  
  350. /***************************************************************************
  351. *                                mouseBox                                  *
  352. ****************************************************************************/
  353. void mouseBox(unsigned left, unsigned top, unsigned right, unsigned bottom)
  354.  
  355. {
  356.     if (left > right)
  357.        swap(&left,&right);
  358.     if (top > bottom)
  359.        swap(&top,&bottom); /* make sure they are ordered */
  360.     reg.r_ax = 7;
  361.     reg.r_cx = left;
  362.     reg.r_dx = right;
  363.     callMouse(); /* set x range */
  364.     reg.r_ax = 8;
  365.     reg.r_cx = top;
  366.     reg.r_dx = bottom;
  367.     callMouse(); /* set y range */
  368. }; /* mouseBox */
  369.  
  370. /***************************************************************************
  371. *                          graphicMouseCursor                              *
  372. ****************************************************************************/
  373. void graphicMouseCursor(char xHotPoint,char yHotPoint,unsigned *dataOfs)
  374.  
  375. /* define 16*16 cursor mask and screen mask, pointed by data,
  376.     dataOfs is pointer to data of the masks. */
  377.  
  378. {
  379.     reg.r_ax = 9;
  380.     reg.r_bx = xHotPoint;
  381.     reg.r_cx = yHotPoint;
  382.     reg.r_dx = FP_OFF(dataOfs);    /* DS:DX point to masks */
  383.     reg.r_es = FP_SEG(dataOfs);
  384.     callMouse();
  385.     lastCursor.xH = xHotPoint;
  386.     lastCursor.yH = yHotPoint;
  387.     lastCursor.data = dataOfs;
  388.     /* save it in lastCursor, if someone needs to change cursor temporary */
  389. }; /* graphicMouseCursor */
  390.  
  391. /***************************************************************************
  392. *                           HardwareTextCursor                             *
  393. ****************************************************************************/
  394. void HardwareTextCursor(char fromLine,char toLine)
  395.  
  396. /* set text cursor to text, using the scan lines from..to,
  397.     same as intr 10 cursor set in bios :
  398.     color scan lines 0..7, monochrome 0..13  */
  399. {
  400.     reg.r_ax = 10;
  401.     reg.r_bx = 1; /* hardware text */
  402.     reg.r_cx = fromLine;
  403.     reg.r_dx = toLine;
  404.     callMouse();
  405. }; /* hardwareTextCursor */
  406.  
  407. /***************************************************************************
  408. *                           softwareTextCursor                             *
  409. ****************************************************************************/
  410. void softwareTextCursor(unsigned screenMask,unsigned cursorMask)
  411.  
  412. /*  when in this mode the cursor will be achived by ANDing the screen word
  413.     with the screen mask (Attr,Char in high,low order) and
  414.     XORing the cursor mask, ussually used by putting the screen attr
  415.     we want preserved in screen mask (and 0 into screen mask character
  416.     byte), and character + attributes we want to set into cursor mask */
  417.  
  418. {
  419.     reg.r_ax = 10;
  420.     reg.r_bx = 0;    /* software cursor */
  421.     reg.r_cx = screenMask;
  422.     reg.r_dx = cursorMask;
  423.     callMouse();
  424. }; /* softwareMouseCursor */
  425.  
  426. /***************************************************************************
  427. *                            recentXmovement                               *
  428. ****************************************************************************/
  429. enum direction recentXmovement (void)
  430. /* from recent call to which direction did we move ? */
  431.  
  432. {
  433.  int  d ;
  434.  
  435.     reg.r_ax = 11;
  436.     callMouse();
  437.     d = reg.r_cx;
  438.     if (d > 0)
  439.         return moveRight;
  440.     else if (d < 0)
  441.         return moveLeft;
  442.     else return noMove;
  443. }; /* recentXmovement */
  444.  
  445. /***************************************************************************
  446. *                            recentYmovement                               *
  447. ****************************************************************************/
  448. enum direction recentYmovement(void)
  449. /* from recent call to which direction did we move ? */
  450. {
  451.    int d;
  452.     reg.r_ax = 11;
  453.     callMouse();
  454.     d = reg.r_dx;
  455.     if (d > 0)
  456.         return moveDown;
  457.     else if (d < 0)
  458.         return moveUp;
  459.     else return noMove;
  460. }; /* recentYmovement */
  461.  
  462. /***************************************************************************
  463. *                             setWatchCursor                               *
  464. ****************************************************************************/
  465. void setWatchCursor (void)
  466. {
  467.     graphicMouseCursor(0, 0, WatchData);
  468. }; /* setWatchCursor */
  469.  
  470. /***************************************************************************
  471. *                             setNewWatchCursor                            *
  472. ****************************************************************************/
  473. void setNewWatchCursor (void)
  474. {
  475.     graphicMouseCursor(0, 0, newWatchCursor);
  476. }; /* setNewWatchCursor */
  477. /***************************************************************************
  478. *                            setUpArrowCursor                              *
  479. ****************************************************************************/
  480. void setUpArrowCursor (void)
  481. {
  482.     graphicMouseCursor(5, 0, UpArrowCursor);
  483. }; /* setUpArrowCursor */
  484.  
  485. /***************************************************************************
  486. *                           setLeftArrowCursor                             *
  487. ****************************************************************************/
  488. void setLeftArrowCursor (void)
  489. {
  490.     graphicMouseCursor(0, 3, LeftArrowCursor);
  491. }; /* setLeftArrowCursor */
  492.  
  493. /***************************************************************************
  494. *                           setCheckMarkCursor                             *
  495. ****************************************************************************/
  496. void setCheckMarkCursor (void)
  497. {
  498.     graphicMouseCursor(6, 7, CheckMarkCursor);
  499. }; /* setCheckMarkCursor */
  500.  
  501. /***************************************************************************
  502. *                         setPointingHandCursor                            *
  503. ****************************************************************************/
  504. void setPointingHandCursor (void)
  505. {
  506.     graphicMouseCursor(5, 0, PointingHandCursor);
  507. }; /* setPointingHandCursor */
  508.  
  509. /***************************************************************************
  510. *                         setDiagonalCrossCursor                           *
  511. ****************************************************************************/
  512. void setDiagonalCrossCursor (void)
  513. {
  514.     graphicMouseCursor(7, 4, DiagonalCrossCursor);
  515. }; /* setDiagonalCrossCursor */
  516.  
  517. /***************************************************************************
  518. *                        setRectangularCrossCursor                          *
  519. ****************************************************************************/
  520. void setRectangularCrossCursor (void)
  521. {
  522.     graphicMouseCursor(7, 4, RectangularCrossCursor);
  523. }; /* setRectangularCrossCursor */
  524.  
  525. /***************************************************************************
  526. *                           setHourGlassCursor                             *
  527. ****************************************************************************/
  528. void setHourGlassCursor (void)
  529. {
  530.     graphicMouseCursor(7, 7, HourGlassCursor);
  531. }; /* setHourGlassCursor */
  532.  
  533. /***************************************************************************
  534. *                             setArrowCursor                               *
  535. ****************************************************************************/
  536. void setArrowCursor (void)
  537. {
  538.     graphicMouseCursor(1, 1, ArrowData);
  539. }; /* setArrowCursor */
  540.  
  541. /***************************************************************************
  542. *                            setEventHandler                               *
  543. ****************************************************************************/
  544. void setEventHandler (unsigned mask ,void interrupt (*handler)())
  545. /* handler must be a far interrupt routine  */
  546.  
  547. {
  548.     reg.r_ax = 12; /* set event handler function in mouse driver */
  549.     reg.r_cx = mask;
  550.     reg.r_es = FP_SEG(handler);
  551.     reg.r_dx = FP_OFF(handler);
  552.     callMouse();
  553.     LastMask = mask;
  554.     lastHandler = handler;
  555. }; /* set event Handler */
  556.  
  557.  
  558. /******************************************************************************
  559. *                               defaultHandler                               *
  560. ******************************************************************************/
  561. void far interrupt defaultHandler (void)
  562. {
  563.    asm   push ds;          /* save TP mouse driver */
  564.    asm   mov ax, SEG _data;
  565.    asm   mov ds, ax;       /* ds = TP:ds, not the driver's ds */
  566.    asm   mov eventX, cx;   /* where in the x region did it occur */
  567.    asm   mov eventY, dx;
  568.    asm   mov eventButtons, bx;
  569.    asm   mov eventhappened, 1; /* eventhapppened = TRUE */
  570.    asm   pop ds;               /* restore driver's ds */
  571.    asm   ret;
  572.  
  573. /*   this is the default event handler , it simulates :
  574.  
  575.       {
  576.            eventX = cx;
  577.            eventY = dx;
  578.            eventButtons = bx;
  579.            eventhappened = True;
  580.       };
  581. */
  582. }
  583.  
  584.  
  585. /***************************************************************************
  586. *                              GetLastEvent                                *
  587. ****************************************************************************/
  588. enum boolean GetLastEvent(unsigned *x, unsigned *y, enum buttonState *left_button,
  589.              enum buttonState *right_button, enum buttonState *middle_button)
  590. {
  591.   enum boolean event = eventhappened ;
  592.  
  593.     eventhappened = FALSE; /* clear to next read/event */
  594.     *x = eventX;
  595.     *y = eventY;
  596.     if ((eventButtons && LEFTBUTTON) != 0)
  597.         *left_button = buttonDown;
  598.     else *left_button = buttonUp;
  599.  
  600.     if ((eventButtons && RIGHTBUTTON) != 0)
  601.         *right_button = buttonDown;
  602.     else *right_button = buttonUp;
  603.     if ((eventButtons && MIDDLEBUTTON) != 0)
  604.         *middle_button = buttonDown;
  605.     else *middle_button = buttonUp;
  606.  
  607.     return event ;
  608. }; /* getLastEvent */
  609.  
  610. /***************************************************************************
  611. *                            setDefaultHandler                              *
  612. ****************************************************************************/
  613. void setDefaultHandler (unsigned mask)
  614.  
  615. /* get only event mask, and set event handler to defaultHandler */
  616.  
  617. {
  618.     setEventHandler(mask, defaultHandler);
  619. }; /* setDefaultHandler */
  620.  
  621. /******************************************************************************
  622. *                           enableLightPenEmulation                           *
  623. ******************************************************************************/
  624. void enableLightPenEmulation (void)
  625.  
  626. {
  627.     reg.r_ax = 13;
  628.     callMouse();
  629. }; /* enableLightPenEmulation */
  630.  
  631. /***************************************************************************
  632. *                        disableLightPenEmulation                          *
  633. ****************************************************************************/
  634. void disableLightPenEmulation (void)
  635.  
  636. {
  637.     reg.r_ax = 14;
  638.     callMouse();
  639. };  /* disableLightPenEmulation */
  640.  
  641. /***************************************************************************
  642. *                           defineSensetivity                              *
  643. ****************************************************************************/
  644. void defineSensetivity(unsigned x, unsigned y)
  645.  
  646. {
  647.     reg.r_ax = 15;
  648.     reg.r_cx = x; /* # of mouse motions to horizontal 8 pixels */
  649.     reg.r_dx = y; /* # of mouse motions to vertical 8 pixels */
  650.     callMouse();
  651.     XMotions = x;
  652.     YMotions = y; /* update global unit variables */
  653. }; /* defineSensetivity */
  654.  
  655. /***************************************************************************
  656. *                            setHideCursorBox                              *
  657. ****************************************************************************/
  658. void setHideCursorBox(unsigned left, unsigned top, unsigned right, unsigned bottom)
  659. {
  660.     reg.r_ax = 16;
  661.     reg.r_es = FP_SEG(&HideBox);
  662.     reg.r_dx = FP_OFF(&HideBox);
  663.     HideBox.left = left;
  664.     HideBox.right = right;
  665.     HideBox.top = top;
  666.     HideBox.bottom = bottom;
  667.     callMouse();
  668. }; /* setHideCursorBox */
  669.  
  670. /***************************************************************************
  671. *                       defineDoubleSpeedTreshHold                         *
  672. ****************************************************************************/
  673. void defineDoubleSpeedTreshHold(unsigned treshHold)
  674. {
  675.     reg.r_ax = 17;
  676.     reg.r_dx = treshHold;
  677.     callMouse();
  678. }; /* defineDoubleSpeedTreshHold - from what speed to double mouse movement */
  679.  
  680. /***************************************************************************
  681. *                            disableTreshHold                              *
  682. ****************************************************************************/
  683. void disableTreshHold (void)
  684. {
  685.     defineDoubleSpeedTreshHold(0x7FFF);
  686. }; /* disableTreshHold */
  687.  
  688. /***************************************************************************
  689. *                            defaultTreshHold                              *
  690. ****************************************************************************/
  691. void defaultTreshHold (void)
  692. {
  693.     defineDoubleSpeedTreshHold(64);
  694. }; /* defaultTreshHold */
  695.  
  696. /***************************************************************************
  697. *                             setMouseGraph                                *
  698. ****************************************************************************/
  699. void setMouseGraph (void)
  700. {
  701.     mouseGraph = TRUE;
  702. }; /* setMouseGraph */
  703.  
  704. /***************************************************************************
  705. *                            resetMouseGraph                               *
  706. ****************************************************************************/
  707. void resetMouseGraph (void)
  708. {
  709.     mouseGraph = FALSE;
  710. }; /* resetMouseGraph */
  711.  
  712.  
  713. /***************************************************************************
  714. *                            waitForRelease                                 *
  715. * Wait until button is release, or timeOut 1/100 seconds pass. (might miss a*
  716. * tenth (1/10) of a second.                                                 *
  717. *****************************************************************************/
  718. void waitForRelease (unsigned timeOut)
  719. {
  720.     struct time st, ct;
  721.     long int stopSec, currentSec, Delta;
  722.  
  723.     gettime(&st);
  724.     stopSec = ((long)st.ti_hour*36000L + (long)st.ti_min*600 +
  725.                (long)st.ti_sec*10 + (long)st.ti_hund + timeOut) % (24*360000L);
  726.     do {
  727.        gettime(&ct);
  728.        currentSec = (long)ct.ti_hour*36000L + (long)ct.ti_min*600 +
  729.                     (long)ct.ti_sec*10 + (long)ct.ti_hund;
  730.        Delta = currentSec - stopSec;
  731.     }
  732.     while (buttonPressed() && Delta > 36000L);
  733. }; /* waitForRelease */
  734.  
  735.  
  736. /****************************************************************************
  737. *                              swapEventHandler                             *
  738. * handler is a far routine.                                                 *
  739. ****************************************************************************/
  740. void swapEventHandler (unsigned mask ,void far interrupt (*handler)())
  741. {
  742.    reg.r_ax = 0x14;
  743.    reg.r_cx = mask;
  744.     reg.r_es = FP_SEG(handler);
  745.     reg.r_dx = FP_OFF(handler);
  746.     callMouse ();
  747.    LastMask = reg.r_cx;
  748.    lastHandler = MK_FP(reg.r_es, reg.r_dx);
  749. }; /*swapEventHandler*/
  750.  
  751. /****************************************************************************
  752. *                            getMouseSaveStateSize                          *
  753. ****************************************************************************/
  754. int getMouseSaveStateSize (void)
  755. {
  756.    reg.r_ax = 0x15;
  757.    callMouse ();
  758.    return (reg.r_bx);
  759. }; /*getMouseSaveStateSize*/
  760.  
  761. /****************************************************************************
  762. *                               interceptMouse                              *
  763. ****************************************************************************/
  764. void interceptMouse (void)
  765. {
  766.    reg.r_ax = 3;
  767.    callMouse (); /* get place .. */
  768.    interceptX = reg.r_cx;
  769.    interceptY = reg.r_dx;
  770.    reg.r_ax = 31;
  771.    callMouse ();
  772. }; /*interceptMouse*/
  773.  
  774. /****************************************************************************
  775. *                                restoreMouse                               *
  776. ****************************************************************************/
  777. void restoreMouse (void)
  778. {
  779.    reg.r_ax = 32; /* restore mouse driver .. */
  780.    callMouse ();
  781.    reg.r_ax = 4;
  782.    reg.r_cx = interceptX;
  783.    reg.r_dx = interceptY;
  784.    callMouse ();
  785. }; /*restoreMouse*/
  786.  
  787.  
  788. /****************************************************************************
  789. *                                 MyExitProc                               *
  790. ****************************************************************************/
  791. void MyExitProc (void)
  792. {
  793. /*    ExitProc = OldExitProc;    ???????????????? */
  794.     resetMouseGraph();
  795.     initMouse();
  796. }; /* myExitProc */
  797.  
  798.